package ch.fusun.baron.basic.client.ui.accountproperty;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import ch.fusun.baron.basic.command.SetDynastyNameCommand;
import ch.fusun.baron.clientapp.login.AccountProperty;
import ch.fusun.baron.core.command.GameCommand;
import ch.fusun.baron.core.rmi.User;
import ch.fusun.baron.player.Dynasty;

/**
 * Let's the user change the name of the {@link Dynasty}
 */
public class DynastyNameAccountProperty implements AccountProperty {

	private String text;

	/**
	 * Kryo
	 */
	public DynastyNameAccountProperty() {
	}

	@Override
	public void createUi(Composite parentArea) {
		new Label(parentArea, SWT.NONE).setText("Dynasty name:"); //$NON-NLS-1$
		final Text textWidget = new Text(parentArea, SWT.BORDER);
		textWidget.addModifyListener(new ModifyListener() {

			@Override
			public void modifyText(ModifyEvent e) {
				text = textWidget.getText();
			}
		});
	}

	@Override
	public GameCommand getCommand(User user) {
		return new SetDynastyNameCommand(text, user);
	}

}
